#include <chrono>
#include <iostream>
#include <thread>

template <size_t N>
class ScopedTimer
{
  public:
    using clock = std::chrono::steady_clock;

    explicit ScopedTimer(char const (&func)[N])
        : func_(func), start_{clock::now()}
    {
    }

    ScopedTimer(const ScopedTimer&) = delete;
    ScopedTimer(ScopedTimer&&) = delete;
    ScopedTimer& operator=(const ScopedTimer&) = delete;
    ScopedTimer& operator=(ScopedTimer&&) = delete;

    ~ScopedTimer()
    {
        using namespace std::chrono;
        auto stop = clock::now();
        auto duration = (stop - start_);
        auto ms = duration_cast<milliseconds>(duration).count();
        std::cout << ms << " ms " << func_ << '\n';
    }

  private:
    const char (&func_)[N];
    const clock::time_point start_{};
};

void fakework()
{
    using namespace std::chrono_literals;
    std::this_thread::sleep_for(1s);
}

using namespace std;
int main(int argc, char** argv)
{
    {
        ScopedTimer a("doing fakework");
        fakework();
        cout << "work finished!!\n";
    }

    return 0;
}
